package com.qiandw

import java.util

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password._
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder

object UsePasswordEncoderFactories{

    final val BCRYPT = "bcrypt"
    final val ldap = "ldap"
    final val MD4 = "MD4"
    final val MD5 = "MD5"
    final val noop = "noop"
    final val PBKDF2 = "pbkdf2"
    final val SCRYPT = "scrypt"
    final val SHA1 = "SHA-1"
    final val SHA256 = "SHA-256"
    final val sha256 = "sha256"

    def createDelegatingPasswordEncoder(encodingId : String = "bcrypt") : PasswordEncoder = {
      val encoders: util.Map[String, PasswordEncoder] = new util.HashMap[String, PasswordEncoder]
        encoders.put("bcrypt", new BCryptPasswordEncoder)
        encoders.put("ldap", new LdapShaPasswordEncoder)
        encoders.put("MD4", new Md4PasswordEncoder)
        encoders.put("MD5", new MessageDigestPasswordEncoder("MD5"))
        encoders.put("noop", NoOpPasswordEncoder.getInstance)
        encoders.put("pbkdf2", new Pbkdf2PasswordEncoder)
        encoders.put("scrypt", new SCryptPasswordEncoder)
        encoders.put("SHA-1", new MessageDigestPasswordEncoder("SHA-1"))
        encoders.put("SHA-256", new MessageDigestPasswordEncoder("SHA-256"))
        encoders.put("sha256", new StandardPasswordEncoder)
       new DelegatingPasswordEncoder(encodingId, encoders)
    }
}
